package com.lagou.servlet;

import com.lagou.service.ClassService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "DeleteClassServlet", value = "/DeleteClassServlet")
public class DeleteClassServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1.设置编码格式
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        //2.获取请求参数
        String del = request.getParameter("del");
        //3.通过Service调用Dao判断是否删除成功
        ClassService classService = new ClassService();
        int i = classService.delClass(del);
        if (i==0){
            //4.删除失败则跳转到失败界面
            System.out.println("删除失败");
            response.sendRedirect("delError.jsp");
        }else{
            //5.删除成功则跳转到信息显示界面
            response.sendRedirect("ClassServlet");
        }
    }
}
